package org.zxp.thread.interrupt;

import org.junit.Test;

/**
 * @program: zxp-thread-test
 * @description: ${description}
 * @author: X-Pacific zhang
 * @create: 2019-05-07 17:27
 **/
public class FlagInterruptTest {
    //volatile关键字变量在每次被线程访问时，都强迫从主内存中重读该变量的值
    //被多线程读取、单线程修改的变量，适合用volitile
    private static volatile boolean flag = false;
    @Test
    public void testFlagInterrupt() throws InterruptedException {
        Thread thread = new Thread(() -> {
           while(!flag){
                System.out.println(Thread.currentThread().getState());
           }
        });
        thread.start();
        Thread.sleep(1000);
        flag = true;
    }
}
